<template>
  <div class="form-layout">
    <!--左侧导航-->
    <div class="nav-left">
      <customAnchor
        :itemList="[
          { name: 'box-base', title: '基础信息' },
          { name: 'box-manage', title: '管理属性' },
          { name: 'box-map', title: '关联信息' },
          { name: 'box-address', title: '收货地址' },
        ]"
      />
    </div>

    <!--表单区域-->
    <div class="form-right" ref="formRight">
      <customForm :data="form" :rules="propRules" ref="editForm" :disabled="propReadonly">
        <template #content>
          <div id="box-base" class="box-title">基础信息</div>
          <customFormItem label="科室名称" name="name" :parent="_self" :form="form"/>
          <customFormItem label="业务类型" name="busType" :parent="_self" :form="form" :type="constCommon.formItemType.selectDict.name" :config="{dictType: constCommon.dictType.baseDeptType}"/>
          <customFormItem label="所属机构" name="officeName" :parent="_self" :form="form" disabled />
          <customFormItem label="科室编号" name="officeSystemCode" :parent="_self" :form="form" disabled/>
          <customFormItem label="科室仓库" name="warehouseName" :parent="_self" :form="form"
                          :readonly="true"
                          :showSelectIcon="true"
                          @focus="utilSelect.warehouse(tableDrawerWarehouseConfirm)"
          />
          <customFormItem label="科室地址" name="addressName" :parent="_self" :form="form"/>
          <customFormItem label="备注" name="remark" :parent="_self" :form="form"/>

          <div id="box-manage" class="box-title">管理属性</div>
          <customFormItem label="业务科室" name="flagBus" :parent="_self" :form="form" :type="constCommon.formItemType.switch.name"   help="如要要使用业务模块请勾选此项" :config="{flagValueBoolean: false}"/>
          <customFormItem label="服务科室" name="flagWarehouse" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="试剂管理" name="flagReagent" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"   help="是否拥有试剂的管理权限" />
          <customFormItem label="查看全院数据" name="flagAllData" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"   help="启用后相关业务和报表将可以看到所有科室数据" :config="{flagValueBoolean: false}"/>
          <customFormItem label="限制请领范围" name="flagApplyLimit" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"  help="启用后科室申请的时候将筛选商品范围" :config="{flagValueBoolean: false}"/>
          <customFormItem label="禁用科室" name="flagDisabled" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name" help="禁用后科室将无法使用，对应的用户也将无法登录" :config="{flagValueBoolean: false}"/>

          <div id="box-map" class="box-title">关联信息</div>
          <customFormItem label="his编码" name="hisCode" :parent="_self" :form="form"/>
          <customFormItem label="his名称" name="hisName" :parent="_self" :form="form"/>
          <customFormItem label="hrp编码" name="hrpCode" :parent="_self" :form="form"/>
          <customFormItem label="hrp名称" name="hrpName" :parent="_self" :form="form"/>
          <customFormItem label="阳采编码" name="sunCode" :parent="_self" :form="form"/>
          <customFormItem label="阳采名称" name="sunCode" :parent="_self" :form="form"/>
        </template>
      </customForm>
      <div id="box-address" class="box-title">收货地址</div>
      <data-view ref="baseDeptAddress"  class='data-view-inlinebtn' @edit-input="editInput" propViewKey="base_dept_address" :propAutoFetchData="false"  />

    </div>
  </div>
</template>

<script>
import customAnchor from '@/components/custom/form/customAnchor.vue'

export default {
  data() {
    return {
      form: {},
      viewData: {}
    }
  },
  created() {
    this.$emit('event-register', {
      validate: callback => {
        return this.$refs.editForm.validate(callback)
      },
      beforeSave: () => {
        this.$emit('data-callback', this.form)
        return true
      },
      afterMove: (formData, initData) => {
        this.form = global.utils.jsonClone(formData)
        this.fetchDataBaseDeptAddress()
      },
      afterSave: () => {
      },
      beforeDelete: () => {
        return true
      },
      afterDelete: () => {},
      beforeFlow: flowButtonKey => {
        return true
      },
      afterFlow: flowButtonKey => {},
      beforeClose: () => {
        return true
      }
    })
  },
  props: {
    propParent: Object,
    propInitData: Object,
    propPrimaryKey: String,
    propDictionaries: Object,
    propCurrentRow: Object,
    propViewFormData: Object,
    propReadonly: Boolean,
    propStatus: String,
    propRules: Object
  },
  components: {customAnchor},
  computed: {},
  methods: {
    fetchDataBaseDeptAddress() {
      let newWrapper
      if (this.form.id) {
        newWrapper = this.$newWrapper().eq('deptId', this.form.id)
      } else {
        newWrapper =  this.$newWrapper().ne(1, 1)
      }
      this.$refs.baseDeptAddress.setQueryWrapper(newWrapper)
    },

    editInput({row, column}) {
      this.$set(row, 'deptId', this.form.id)
    },
    // 仓库选择确认
    tableDrawerWarehouseConfirm(row) {
      this.$set(this.form, 'warehouseId', row.id)
      this.$set(this.form, 'warehouseName', row.name)
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  width: 100%;
  height: 100%;
}
</style>
